#ifndef _DATAPACKET_H
#define _DATAPACKET_H
#include <iostream>
#include "xByteBuffer.h"

namespace xNet
{
    class DataPacket : public xByteBuffer{
    public:
        
        DataPacket(): xByteBuffer(1024), m_opcode(0)
        {
        }
        
        explicit DataPacket(uint16_t opcode, size_t res=1024) : xByteBuffer(res), m_opcode(opcode)
        { 
        }
        
        // copy constructor
        DataPacket(const DataPacket &packet) : xByteBuffer(packet), m_opcode(packet.m_opcode)
        {
        }
        
        void initialize(uint16_t opcode, size_t initSize=1024)
        {
            _storage.resize(initSize);
            m_opcode = opcode;
        }
        
        uint16_t getOpcode() const { return m_opcode; }
        void setOpcode(uint16_t opcode) { m_opcode = opcode; }
    protected:
        uint16_t m_opcode;
    };
}

#endif